package com.octopus.tree.imp.simple.test;

import static org.junit.Assert.*;

import java.util.List;
import java.util.Properties;

import javax.xml.bind.JAXBException;

import org.junit.Test;

import com.octopus.tree.TreeBranch;
import com.octopus.tree.TreeLeaf;
import com.octopus.tree.imp.simple.AlreadyInTreeStructureException;
import com.octopus.tree.imp.simple.DefaultSameNameTreeBranchAlreadyExist;
import com.octopus.tree.imp.simple.DefaultSameNameTreeLeafAlreadyExist;
import com.octopus.tree.imp.simple.NameAlreadyExistException;
import com.octopus.tree.imp.simple.NameIsNullException;
import com.octopus.tree.imp.simple.TreeBranchImp;
import com.octopus.tree.imp.simple.TreeImp;
import com.octopus.tree.imp.simple.TreeLeafImp;

public class SimpleTreeTestCase {

	@Test
	public void simpleTreeConstructor() {
		TreeImp ti = new TreeImp();
		String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"root\"><xp value=\"\" key=\"_system_root\"/></n></root>"; 
		assertEquals(expected, ti.toString());
		
	}
	
	@Test
	public void simpleTreeConstructorWithString(){
		TreeImp ti = new TreeImp("testroot");
		String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expected, ti.toString());
	}
	
	@Test
	public void simpleTreeAddPathAndContent(){
		TreeImp ti = new TreeImp("testroot");
		TreeBranch tb = ti.createSimpleSubTreeBranch("com.octopus.tree.simple.test");
		TreeLeafImp tli = new TreeLeafImp("leaf1", null, null, null);
		tli.setTreeLeafProperty("key1", "value1");
		tli.setObjectContent("hello this is the first test content");
		try {
			tb.addTreeLeaf(tli);
		} catch (AlreadyInTreeStructureException e) {
			fail("AlreadyInTreeStructureException shouldn't be thrown out");
		} catch (NameAlreadyExistException e) {
			fail("NameAlreadyExistException shouldn't be thrown out");
		}
		String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expected, ti.toPermanent());
	}
	
	@Test
	public void simpleCreateTreeFromXmlString(){
		String rootString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		TreeImp ti = null;
		try {
			ti = new TreeImp(rootString, true);
		} catch (JAXBException e) {
			e.printStackTrace();
			fail();
		}
		assertEquals(rootString, ti.toPermanent());
	}
	
	@Test
	public void addNewBranchNewLeafAndDetach(){
		String rootString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		TreeImp ti = null;
		try {
			ti = new TreeImp(rootString, true);
		} catch (JAXBException e) {
			e.printStackTrace();
			fail("JAXBException");
		}
		TreeBranch tb2 = ti.createSimpleSubTreeBranch("level1.level2.level3");
		TreeBranch tb3 = ti.createSimpleSubTreeBranch("level1.level2.level4");
		String expectedString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/><n name=\"level4\"/></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString, ti.toPermanent());
		tb3.detach();
		String expectedString2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString2, ti.toPermanent());
		TreeBranch tb4 = ti.createSimpleSubTreeBranch("level1.level2.level5");
		TreeBranch tb5 = ti.createSimpleSubTreeBranch("level1.level2.level6");
		TreeBranch tb6 = ti.createSimpleSubTreeBranch("level1.level2.level6");
		TreeLeafImp tli = new TreeLeafImp("leaf2", null, null, null);
		tli.setTreeLeafProperty("key2", "value2");
		try {
			tb6.addTreeLeaf(tli);
		} catch (AlreadyInTreeStructureException e) {
			fail("AlreadyInTreeStructureException");
		} catch (NameAlreadyExistException e) {
			fail("NameAlreadyExistException");
		}
		String expectedString3 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/><n name=\"level5\"/><n name=\"level6\"><node name=\"leaf2\"><xp value=\"value2\" key=\"key2\"/></node></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString3, ti.toPermanent());
		tli.setObjectContent("another test String");
		String expectedString4 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/><n name=\"level5\"/><n name=\"level6\"><node name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/></node></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString4, ti.toPermanent());
		
		List<TreeLeaf> leafList = ti.findTreeLeaf("/com/octopus/tree/simple/test/leaf1");
		assertNotNull(leafList);
		assertEquals(1, leafList.size());
		
		String expectedString5 = "hello this is the first test content";
		assertEquals(expectedString5, leafList.get(0).getObjectContent());
		
		TreeLeafImp tli2 = new TreeLeafImp("leaf2", null, null, null);
		tli2.setTreeLeafProperty("key2", "value2");
		tli2.setTreeLeafProperty("position", "2");
		Object tempFlag = null;
		try {
			tb6.addTreeLeaf(tli2);
		} catch (AlreadyInTreeStructureException e) {
			fail("AlreadyInTreeStructureException");
		} catch (NameAlreadyExistException e) {
			tempFlag = new Object();
		}
		assertNotNull(tempFlag);
		
		TreeLeafImp tli3 = new TreeLeafImp("leaf2", null, null, null);
		tli3.setObjectContent(new Integer("1"));
		tli3.setKind("KIND_2");
		tli3.setTreeLeafProperty("key2", "value2");
		try {
			tb6.addTreeLeaf(tli3);
		} catch (AlreadyInTreeStructureException e) {
			fail("AlreadyInTreeStructureException");
		} catch (NameAlreadyExistException e) {
			fail("NameAlreadyExistException");
		}
		String expectedString6 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/><n name=\"level5\"/><n name=\"level6\"><node name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/></node></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString6, ti.toPermanent());
		Properties p = new Properties();
		p.setProperty("jintian", "jintianjintian");
		TreeLeafImp tli4 = new TreeLeafImp("leaf2","KIND_2", "t4", p);
		try {
			tb6.addTreeLeaf(tli4);
		} catch (AlreadyInTreeStructureException e) {
			fail("AlreadyInTreeStructureException");
		} catch (NameAlreadyExistException e) {
			fail("NameAlreadyExistException");
		}
		
		String expectedString7 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/><n name=\"level5\"/><n name=\"level6\"><node name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/></node></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString7, ti.toPermanent());
		
		List<TreeLeaf> leafList2 = ti.findTreeLeaf("/level1/level2/level6/leaf2");
		tli.setTreeLeafProperty("position", "1");
		tli3.setTreeLeafProperty("position", "3");
		tli4.setTreeLeafProperty("position", "4");
		assertEquals(3, leafList2.size());
		
		List<TreeLeaf> leafList3 = ti.findTreeLeaf("/level1/level2/level6/leaf2[{position:3}]");
		assertEquals(1, leafList3.size());
		assertEquals(tli3.getObjectContent(), leafList3.get(0).getObjectContent());
		
		List<TreeLeaf> leafList4 = ti.findTreeLeaf("/level1/level2/level6/leaf2[{position:4}]");
		assertEquals(1, leafList4.size());
		assertEquals(tli4.getObjectContent(), leafList4.get(0).getObjectContent());
		
		List<TreeLeaf> leafList5 = ti.findTreeLeaf("/level1/level2/level6/leaf2[{position:1}]");
		assertEquals(1, leafList5.size());
		assertEquals(tli.getObjectContent(), leafList5.get(0).getObjectContent());
		
		List<TreeLeaf> leafList6 = ti.findTreeLeaf("/level1/level2/level6/leaf2[index=2]");
		assertEquals(1, leafList6.size());
		assertEquals(tli4.getObjectContent(), leafList6.get(0).getObjectContent());
		
		List<TreeLeaf> leafList7 = ti.findTreeLeaf("/level1/level2/level6/leaf2[index=1-2]");
		assertEquals(2, leafList7.size());
		assertEquals(tli3.getObjectContent(), leafList7.get(0).getObjectContent());
		assertEquals(tli4.getObjectContent(), leafList7.get(1).getObjectContent());
		
		List<TreeLeaf> leafList8 = ti.findTreeLeaf("/level1[kind=$default]/level2[kind=$default]/level6/leaf2[index=1-2, {position:4}]");
		assertEquals(1, leafList8.size());
		assertEquals(tli4.getObjectContent(), leafList8.get(0).getObjectContent());
		
		List<TreeBranch> findTBL = ti.findTreeBranch("/level1/level2");
		assertEquals(1, findTBL.size());
		TreeBranchImp tbi = new TreeBranchImp("level6", "TreeBranchKind", null);
		tbi.setTreeBranchProperty("tk1", "tk1_value");
		boolean addBranchResult = false;
		try {
			addBranchResult = findTBL.get(0).addTreeBranch(tbi);
		} catch (NameAlreadyExistException e) {
			fail("NameAlreadyExistException");
		} catch (AlreadyInTreeStructureException e) {
			fail("AlreadyInTreeStructureException");
		}
		assertTrue(addBranchResult);
		String expectedString8 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/><n name=\"level5\"/><n name=\"level6\"><node name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n kind=\"TreeBranchKind\" name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString8, ti.toPermanent());
		
		List<TreeBranch> leafBranch1 = ti.findTreeBranch("/level1/level2/level6[kind=TreeBranchKind]");
		assertEquals(1, leafBranch1.size());
		assertEquals("tk1_value", leafBranch1.get(0).getTreeBranchProperty("tk1"));
		tb4.setTreeBranchKind("ILOP");
		String expectedString9 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/><n kind=\"ILOP\" name=\"level5\"/><n name=\"level6\"><node name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n kind=\"TreeBranchKind\" name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString9, ti.toPermanent());
		List<TreeBranch> leafBranch1_2 = ti.findTreeBranch("/level1/level2/level5[kind=ILOP]");
		List<TreeBranch> leafBranch1_3 = ti.findTreeBranch("/level1/level2/level5[kind=$default]");
		assertEquals(1, leafBranch1_2.size());
		assertEquals("ILOP", leafBranch1_2.get(0).getTreeBranchKind());
		assertNull(leafBranch1_3);
		
		tb4.setTreeBranchKind(null);
		String expectedString10 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/><n name=\"level5\"/><n name=\"level6\"><node name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n kind=\"TreeBranchKind\" name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString10, ti.toPermanent());
		List<TreeBranch> leafBranch1_2_1 = ti.findTreeBranch("/level1/level2/level5[kind=ILOP]");
		List<TreeBranch> leafBranch1_3_1 = ti.findTreeBranch("/level1/level2/level5[kind=$default]");
		assertEquals(1, leafBranch1_3_1.size());
		assertNull(leafBranch1_3_1.get(0).getTreeBranchKind());
		assertNull(leafBranch1_2_1);
		
		tb5.setTreeBranchKind("TreeBranchKind2");
		String expectedString_19_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/><n name=\"level5\"/><n kind=\"TreeBranchKind2\" name=\"level6\"><node name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n kind=\"TreeBranchKind\" name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString_19_1, ti.toPermanent());
		List<TreeBranch> leafBranch1_19_1 = ti.findTreeBranch("/level1/level2/level6[kind=TreeBranchKind2]");
		List<TreeBranch> leafBranch1_19_2 = ti.findTreeBranch("/level1/level2/level6[kind=TreeBranchKind]");
		assertEquals(1, leafBranch1_19_1.size());
		assertEquals(1, leafBranch1_19_2.size());
		assertEquals("TreeBranchKind2", leafBranch1_19_1.get(0).getTreeBranchKind());
		assertEquals("TreeBranchKind", leafBranch1_19_2.get(0).getTreeBranchKind());
		assertEquals("level6", leafBranch1_19_1.get(0).getTreeBranchName());
		assertEquals("level6", leafBranch1_19_2.get(0).getTreeBranchName());
		
		tbi.setTreeBranchKind(null);
		boolean canNotSetKindToDefault = false;
		try{
			tb5.setTreeBranchKind(null);
		}catch(DefaultSameNameTreeBranchAlreadyExist e){
			canNotSetKindToDefault = true;
		}
		assertTrue(canNotSetKindToDefault);
		String expectedString_19_2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/><n name=\"level5\"/><n kind=\"TreeBranchKind2\" name=\"level6\"><node name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString_19_2, ti.toPermanent());
		
		tbi.setTreeBranchKind("TXY");
		tb5.setTreeBranchKind("TXY");
		
		String expectedString_19_3 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/><n name=\"level5\"/><n kind=\"TXY\" name=\"level6\"><node name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_2\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n kind=\"TXY\" name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString_19_3, ti.toPermanent());
		
		List<TreeBranch> leafBranch1_19_4 = ti.findTreeBranch("/level1/level2/level6[kind=TXY]");
		assertEquals(2, leafBranch1_19_4.size());
		assertEquals(0, leafBranch1_19_4.get(0).getTreeBranchProperties().size());
		assertEquals(1, leafBranch1_19_4.get(1).getTreeBranchProperties().size());
		//tli.setTreeLeafKind(kind);
		//tli4.setTreeLeafKind(kind);
		
		boolean leafAlreayExist = false;
		try{
			tli3.setTreeLeafKind(null);
		}catch(DefaultSameNameTreeLeafAlreadyExist e){
			leafAlreayExist = true;
		}
		assertTrue(leafAlreayExist);
		tli3.setTreeLeafKind("KIND_3");
		List<TreeLeaf> leafBranch1_19_5 = ti.findTreeLeaf("/level1/level2/level6[kind=TXY]/leaf2[kind=KIND_3]");
		assertEquals(1, leafBranch1_19_5.size());
		assertEquals(1, leafBranch1_19_5.get(0).getObjectContent());
		
		tli.setKind("KIND_4");
		tli4.setKind("KIND_4");
		tli3.setKind(null);
		List<TreeLeaf> leafBranch1_19_6 = ti.findTreeLeaf("/level1/level2/level6[kind=TXY]/leaf2[kind=$default]");
		List<TreeLeaf> leafBranch1_19_7 = ti.findTreeLeaf("/level1/level2/level6[kind=TXY]/leaf2[kind=KIND_4]");
		assertEquals(1, leafBranch1_19_6.size());
		assertEquals(2, leafBranch1_19_7.size());
		assertEquals(tli3.getObjectContent(), leafBranch1_19_6.get(0).getObjectContent());
		assertEquals(tli.getObjectContent(), leafBranch1_19_7.get(0).getObjectContent());
		assertEquals(tli4.getObjectContent(), leafBranch1_19_7.get(1).getObjectContent());
		String expectedString_19_8 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"level3\"/><n name=\"level5\"/><n kind=\"TXY\" name=\"level6\"><node kind=\"KIND_4\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_4\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n kind=\"TXY\" name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString_19_8, ti.toPermanent());
		
		tb2.setTreeBranchName("tb2");
		String expectedString_20_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"tb2\"/><n name=\"level5\"/><n kind=\"TXY\" name=\"level6\"><node kind=\"KIND_4\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_4\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n kind=\"TXY\" name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>"; 
		assertEquals(expectedString_20_1, ti.toPermanent());
		boolean throwE1 = false;
		try{
			tb4.setTreeBranchName("tb2");
		}catch(DefaultSameNameTreeBranchAlreadyExist e){
			throwE1 = true;
		}
		assertTrue(throwE1);
		
		boolean throwE2 = false;
		try{
			tb4.setTreeBranchName(null);
		}catch(NameIsNullException e){
			throwE2 = true;
		}
		assertTrue(throwE2);
		
		boolean throwE3 = false;
		try{
			tb4.setTreeBranchName(" ");
		}catch(NameIsNullException e){
			throwE3 = true;
		}
		assertTrue(throwE3);
		
		tb5.setTreeBranchName("tb5");
		String expectedString_20_2 ="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"tb2\"/><n name=\"level5\"/><n kind=\"TXY\" name=\"tb5\"><node kind=\"KIND_4\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_4\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n kind=\"TXY\" name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString_20_2, ti.toPermanent());
		
		List<TreeBranch> leafBranch10_20_1 = ti.findTreeBranch("/level1/level2/tb2[kind=$default]");
		List<TreeBranch> leafBranch10_20_2 = ti.findTreeBranch("/level1/level2/tb2");
		List<TreeBranch> leafBranch10_20_3 = ti.findTreeBranch("/level1/level2/level5");
		List<TreeBranch> leafBranch10_20_4 = ti.findTreeBranch("/level1/level2/tb5[kind=$default]");
		List<TreeBranch> leafBranch10_20_5 = ti.findTreeBranch("/level1/level2/tb5[kind=TXY]");
		List<TreeBranch> leafBranch10_20_6 = ti.findTreeBranch("/level1/level2/tb5");
		List<TreeBranch> leafBranch10_20_7 = ti.findTreeBranch("/level1/level2/level6");
		List<TreeBranch> leafBranch10_20_8 = ti.findTreeBranch("/level1/level2/level6[kind=TXY]");
		assertEquals(1, leafBranch10_20_1.size());
		assertEquals("tb2", leafBranch10_20_1.get(0).getTreeBranchName());
		assertEquals(1, leafBranch10_20_2.size());
		assertEquals("tb2", leafBranch10_20_2.get(0).getTreeBranchName());
		assertEquals(leafBranch10_20_1.get(0), leafBranch10_20_2.get(0));
		assertNull(leafBranch10_20_2.get(0).getTreeBranchKind());
		assertEquals(1, leafBranch10_20_3.size());
		assertEquals("level5", leafBranch10_20_3.get(0).getTreeBranchName());
		assertNull(leafBranch10_20_4);
		assertEquals(1, leafBranch10_20_5.size());
		assertEquals("tb5", leafBranch10_20_5.get(0).getTreeBranchName());
		assertEquals(1, leafBranch10_20_6.size());
		assertEquals("tb5", leafBranch10_20_6.get(0).getTreeBranchName());
		assertEquals(leafBranch10_20_5.get(0), leafBranch10_20_6.get(0));
		assertEquals("TXY", leafBranch10_20_5.get(0).getTreeBranchKind());
		assertEquals(1, leafBranch10_20_7.size());
		assertEquals("level6", leafBranch10_20_7.get(0).getTreeBranchName());
		assertEquals(1, leafBranch10_20_8.size());
		assertEquals("level6", leafBranch10_20_8.get(0).getTreeBranchName());
		assertEquals("TXY", leafBranch10_20_8.get(0).getTreeBranchKind());
		
		
		tli.setTreeLeafName("tli");
		
		String expectedString_20_3 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"tb2\"/><n name=\"level5\"/><n kind=\"TXY\" name=\"tb5\"><node kind=\"KIND_4\" name=\"tli\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_4\" name=\"leaf2\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n kind=\"TXY\" name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString_20_3, ti.toPermanent());
		
		tli4.setTreeLeafName("tli4");
		String expectedString_20_4 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"tb2\"/><n name=\"level5\"/><n kind=\"TXY\" name=\"tb5\"><node kind=\"KIND_4\" name=\"tli\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node name=\"leaf2\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_4\" name=\"tli4\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n kind=\"TXY\" name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString_20_4, ti.toPermanent());
		
		tli3.setTreeLeafName("tli3");
		String expectedString_20_5 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"tb2\"/><n name=\"level5\"/><n kind=\"TXY\" name=\"tb5\"><node kind=\"KIND_4\" name=\"tli\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node name=\"tli3\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_4\" name=\"tli4\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n kind=\"TXY\" name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString_20_5, ti.toPermanent());
		
		tli.setTreeLeafKind(null);
		
		boolean exception_throw_1 = false; 
		try{
			tli3.setTreeLeafName("tli");
		}catch(DefaultSameNameTreeLeafAlreadyExist e){
			exception_throw_1 = true;
		}
		assertTrue(exception_throw_1);
		
		boolean exception_throw_2 = false; 
		try{
			tli3.setTreeLeafName(null);
		}catch(NameIsNullException e){
			exception_throw_2 = true;
		}
		assertTrue(exception_throw_2);
		
		boolean exception_throw_3 = false; 
		try{
			tli3.setTreeLeafName(" ");
		}catch(NameIsNullException e){
			exception_throw_3 = true;
		}
		assertTrue(exception_throw_3);
		
		String expectedString_20_6 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><root xmlns=\"octopus.internal.tree\"><n name=\"testroot\"><n name=\"com\"><n name=\"octopus\"><n name=\"tree\"><n name=\"simple\"><n name=\"test\"><node name=\"leaf1\"><contentType>java.lang.String</contentType><content>rO0ABXQAJGhlbGxvIHRoaXMgaXMgdGhlIGZpcnN0IHRlc3QgY29udGVudA==</content><xp value=\"value1\" key=\"key1\"/></node></n></n></n></n></n><n name=\"level1\"><n name=\"level2\"><n name=\"tb2\"/><n name=\"level5\"/><n kind=\"TXY\" name=\"tb5\"><node name=\"tli\"><contentType>java.lang.String</contentType><content>rO0ABXQAE2Fub3RoZXIgdGVzdCBTdHJpbmc=</content><xp value=\"value2\" key=\"key2\"/><xp value=\"1\" key=\"position\"/></node><node name=\"tli3\"><contentType>java.lang.Integer</contentType><content>rO0ABXNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAB</content><xp value=\"value2\" key=\"key2\"/><xp value=\"3\" key=\"position\"/></node><node kind=\"KIND_4\" name=\"tli4\"><contentType>java.lang.String</contentType><content>rO0ABXQAAnQ0</content><xp value=\"jintianjintian\" key=\"jintian\"/><xp value=\"4\" key=\"position\"/></node></n><n kind=\"TXY\" name=\"level6\"><xp value=\"tk1_value\" key=\"tk1\"/></n></n></n><xp value=\"\" key=\"_system_root\"/></n></root>";
		assertEquals(expectedString_20_6, ti.toPermanent());
		
		tli3.setTreeLeafName("tli4");
		List<TreeLeaf> leafBranch10_20_09 = ti.findTreeLeaf("/level1/level2/tb5/tli[kind=$default]");
		List<TreeLeaf> leafBranch10_20_10 = ti.findTreeLeaf("/level1/level2/tb5/tli");
		List<TreeLeaf> leafBranch10_20_11 = ti.findTreeLeaf("/level1/level2/tb5/tli3");
		List<TreeLeaf> leafBranch10_20_12 = ti.findTreeLeaf("/level1/level2/tb5/tli3[kind=$default]");
		List<TreeLeaf> leafBranch10_20_13 = ti.findTreeLeaf("/level1/level2/tb5/tli3[kind=TXY]");
		List<TreeLeaf> leafBranch10_20_14 = ti.findTreeLeaf("/level1/level2/tb5/tli4");
		List<TreeLeaf> leafBranch10_20_15 = ti.findTreeLeaf("/level1/level2/tb5/tli4[kind=$default]");
		List<TreeLeaf> leafBranch10_20_16 = ti.findTreeLeaf("/level1/level2/tb5/tli4[kind=KIND_4]");
		assertEquals(1, leafBranch10_20_09.size());
		assertEquals("tli", leafBranch10_20_09.get(0).getTreeLeafName());
		assertEquals(1, leafBranch10_20_10.size());
		assertEquals("tli", leafBranch10_20_10.get(0).getTreeLeafName());
		assertEquals(leafBranch10_20_09.get(0), leafBranch10_20_10.get(0));
		assertNull(leafBranch10_20_09.get(0).getTreeLeafKind());
		
		assertNull(leafBranch10_20_11);
		assertNull(leafBranch10_20_12);
		assertNull(leafBranch10_20_13);
		
		assertEquals(2, leafBranch10_20_14.size());
		assertEquals("tli4", leafBranch10_20_14.get(0).getTreeLeafName());
		assertEquals("tli4", leafBranch10_20_14.get(1).getTreeLeafName());
		assertEquals(1, leafBranch10_20_15.size());
		assertEquals(1, leafBranch10_20_16.size());
		assertEquals("tli4", leafBranch10_20_15.get(0).getTreeLeafName());
		assertEquals("3", leafBranch10_20_15.get(0).getTreeLeafProperty("position"));
		assertEquals(1, leafBranch10_20_15.get(0).getObjectContent());
		assertEquals("4", leafBranch10_20_16.get(0).getTreeLeafProperty("position"));
		assertEquals("KIND_4", leafBranch10_20_16.get(0).getTreeLeafKind());
		assertEquals("t4", leafBranch10_20_16.get(0).getObjectContent());
		
		System.out.println(ti.toPermanent());
	}

}
